<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

if ($_GET['a']==1) {
	$deletesql = "DELETE FROM tblrelatedproduct WHERE intid=".mysql_real_escape_string($_GET['rid']);
	mysql_query($deletesql);
	header("location:relatedproducts.php?msg=del");
	die();
}
	
?>
<?php include("inc/header.php");?>
<body>

 <form name="special" action="" method="post">	
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="96%">
	<br /><br />
	<table width="80%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
      <tr class="bg1">
	  	
        <td height="18" colspan="5" align="left"><strong>Related Products...</strong></td>
      </tr>
		

      <tr>
        <td>&nbsp;</td>
        <td align="right" class="sltimg">&nbsp;</td>
        <td>&nbsp;</td>
        <td align="left">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td width="2%">&nbsp;</td>
        <td width="16%" align="right" class="sltimg">Products</td>
        <td width="5%">:</td>
        <td width="68%" align="left"><select name="relate" id="relate" onChange="document.special.submit();">
          <option value="0">Products</option>
          <?php 
		  $relate=0;
		  if(isset($_REQUEST['relate']))
				{
					$relate=mysql_real_escape_string($_REQUEST['relate']);
				}
			$sql55="select * from tblproducts";
			$resultpr = $obj_db->select($sql55);
			if(count($resultpr)>0)
			{
				for($p=0;$p<count($resultpr);$p++)
				{
						$relprid=$resultpr[$p]['intprodid'];		
					?>
         <option value="<?php echo $resultpr[$p]['intprodid'];?>"<?php if($resultpr[$p]['intprodid'] == $relate){echo "selected";}else{echo "";} ?>>
            <?php echo $resultpr[$p]['intprodid']; ?>            </option>
          <?php 
							}
						}
					?>
        </select></td>
        <td width="9%">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5" align="left">
	
				
			  <?php
			if(isset($_REQUEST['relate']) && ($_REQUEST['relate'])!=0)
				{
				
					$reid=mysql_real_escape_string($_REQUEST['relate']);
					$sql0="select * from tblrelatedproduct where intprodid='$reid'";
					$resrelated=$obj_db->select($sql0);
					if(count($resrelated)>0)
					{
					?>
					<table width="100%" border="0" align="center" cellpadding="0" cellspacing="2" class="border">
			    <tr>
				<td height="22" align="center" class="tblbg3"><strong class="tblbg3">Product Name </strong></td>
				<td align="center" class="tblbg3"><strong class="tblbg3">Product Description </strong></td>
				<td align="center" class="tblbg3"><strong class="tblbg3">Delete</strong></td>
				</tr>
					<?php
						for($r=0;$r<count($resrelated);$r++)
						{
							$relid= $resrelated[$r]['intrelatedid'];
							$sql01="select * from tblproddesc where intid='$relid'";
							$relname=$obj_db->select($sql01);
							if(count($relname)>0)
							{
								for($r1=0;$r1<count($relname);$r1++)
								{
								?>
								<tr class="<?php echo ($r%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';" onMouseOut="this.className='<?php echo ($r%2==0)?"Hrnormal":"Hralter"; ?>';" height="18">
								<td align="center"><?php echo $relname[$r1]['varprodname'];?></td>
								<td width="49%" align="center"><?php
								  $desctxt=stripslashes($relname[$r1]['txtdesc']);
									 if(strlen($desctxt) > 20 ) {
										$desctxt=substr($desctxt,0,20);
										$desctxt=$desctxt."...";
									  }			  
									  echo srchwordchangestyl($desctxt);
									  ?></td>
									<td align="center"><a href="relatedproducts.php?a=1&rid=<?php echo $resrelated[$r]['intid'];?>"><img src="images/delete.bmp" border="0"></a></td>
								</tr>
								 
			  <?php
									
								}
							}		
						}
					
					?>
					
					<?php
					}
					else
					{
					?>
					<tr>
					<td colspan="5" align="center" class="Hralter fontwhite">
					No Related Products for this product.					</td>
					</tr>
			  <?php
						
					}
				}
			
		?></table>		</td>
      </tr>
      <tr>
        <td colspan="5" align="center">&nbsp;</td>
      </tr>
    </table></td>
    <td width="2%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" align="center">&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>
